package form.ui.core
{
	import flash.display.Stage;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class Screen extends FMSprite
	{
		protected var currentStage:Stage;
		
		public function Screen()
		{
			super();
			
			this.mouseEnabled = true;
			
			this.addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
			
		}
		
		protected function onAddedToStage(e:Event):void {
			this.currentStage = this.stage;
			
			this.onResize();
			
			this.currentStage.addEventListener(Event.RESIZE, this.onResize);
		}
		
		protected function onRemovedFromStage(e:Event):void {
			this.currentStage.removeEventListener(Event.RESIZE, this.onResize);	
			this.currentStage = null;
		}
		
		protected function onResize(e:Event = null):void {
			var origin:Point = this.globalToLocal(new Point(0, 0));
			this.x = origin.x;
			this.y = origin.y;
			
			this.width = this.currentStage.stageWidth;
			this.height = this.currentStage.stageHeight;
		}	
	}
}